package java.wxw;

import sun.rmi.runtime.NewThreadAction;

import java.io.FileWriter;
import java.util.Scanner;

/**
 * @author wangxianwei
 * @create 2020--06--19--17:02
 */
//关闭文件
public class CloseFile extends Final{
    String fileName;
    int i, k;
    FileExist fileExist = new FileExist();
    DirExist dirExist = new DirExist();
    public CloseFile() {
    }
    public void closeFile(){
        if(!dirName.equals(userName)){
            System.out.println("Error!You can only modify filemode in yourself dir.");

        }else{//用户名和当前目录相同了
            System.out.println("Please input FileName");
            Scanner in = new Scanner(System.in);
            fileName = in.next();
            i = fileExist.fileExsit(fileName);   //文件是否存在并返回第几个文件号
            if(i>=0) { //文件不存在
                k=dirExist.dirExist(userName);  //根据用户名确定用户号
                if(openIf[k][i].openIf == 0) { //该文件未打开
                    System.out.println("Error!"+fileName+" has been closed.You can not close it again");

                }else{ //该文件已打开
                    openIf[k][i].openIf = 0; //关闭置为0
                    openIf[k][i].openMode=4;//修改打开模式为初始的打开模式
                    System.out.println(fileName+"has been closed successfully!");

                }
            }else{
                //文件不存在
                System.out.println(fileName+" dose not exist!");
            }
        }
    }
}
